﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 会员卡管理系统
{
    public partial class RecordManage : UserControl
    {
        public RecordManage()
        {
            InitializeComponent();
        }
        Vipclass.tb_viphouseinfo RecordInfo = new Vipclass.tb_viphouseinfo();
        Vipclass.tbVipHouseMenthod RecordMenthod = new Vipclass.tbVipHouseMenthod();
        private void RecordManage_Load(object sender, EventArgs e)
        {
            RecordMenthod.tbMainRecordfoFill(lvMainRecord);
        }

        private void lvMainRecord_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                if(lvMainRecord.SelectedItems.Count>0)
                {
                    
                    string strshow =lvMainRecord.SelectedItems[0].SubItems[0].Text;
                    RecordInfo= RecordMenthod.tbRecordtoshow(strshow);
                    labhouseid.Text = RecordInfo.Strhouseid;
                    labvipname.Text = RecordInfo.Strvipname;
                    labvipid.Text = RecordInfo.Strvipid;
                    labvipidcard.Text = RecordInfo.Strvipidcard;
                    labusedate.Text = RecordInfo.Dtusedate.ToLongDateString();
                    lableavedate.Text = RecordInfo.Dtleavedate.ToLongDateString();
                }
            }
            catch(Exception err)
            {
                MessageBox.Show(err.Message.ToString());
            }
        }

        private void 刷新ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            RecordMenthod.tbMainRecordfoFill(lvMainRecord);
        }

        private void 删除ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (lvMainRecord.SelectedItems.Count > 0)
            {
                string strshow = lvMainRecord.SelectedItems[0].SubItems[0].Text;
                if (MessageBox.Show("是否删除此条记录？", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                {
                    if (RecordMenthod.tbrecordfodel(strshow) == 1)
                    {
                        MessageBox.Show("删除成功！", "提示");
                    }
                    else
                    {
                        MessageBox.Show("删除失败！", "错误");
                    }
                }
                else
                {
                    return;
                }
                RecordMenthod.tbMainRecordfoFill(lvMainRecord);
            }
            else
            {
                MessageBox.Show("未选中删除项！", "提示");
            }

        }

        private void btnDelRecord_Click(object sender, EventArgs e)
        {
            if (lvMainRecord.SelectedItems.Count > 0)
            {
                string strshow = lvMainRecord.SelectedItems[0].SubItems[0].Text;
                if (MessageBox.Show("是否删除此条记录？", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                {
                    if (RecordMenthod.tbrecordfodel(strshow) == 1)
                    {
                        MessageBox.Show("删除成功！", "提示");
                    }
                    else
                    {
                        MessageBox.Show("删除失败！", "错误");
                    }
                }
                else
                {
                    return;
                }
                RecordMenthod.tbMainRecordfoFill(lvMainRecord);
            }
            else
            {
                MessageBox.Show("未选中删除项！", "提示");
            }
        }

        private void tbxReserch_TextChanged(object sender, EventArgs e)
        {
            int way = 0;
            if (rbtHouse.Checked == true)
            {
                way = 0;
            }
            else
            {
                if(rbtName.Checked==true)
                {
                    way = 1;
                }
                else
                {
                    if(rbtIdcard.Checked==true)
                    {
                        way = 2;
                    }
                    else
                    {
                        way = 3;
                    }
                }
            }
            RecordMenthod.tbRecordfoFind(lvMainRecord, tbxReserch.Text.Trim(),way,dateStart.Value.ToShortDateString(),dateStop.Value.ToShortDateString());
        }

        private void dateStart_ValueChanged(object sender, EventArgs e)
        {
            int way = 0;
            if (rbtHouse.Checked == true)
            {
                way = 0;
            }
            else
            {
                if (rbtName.Checked == true)
                {
                    way = 1;
                }
                else
                {
                    if (rbtIdcard.Checked == true)
                    {
                        way = 2;
                    }
                    else
                    {
                        way = 3;
                    }
                }
            }
            RecordMenthod.tbRecordfoFind(lvMainRecord, tbxReserch.Text.Trim(), way, dateStart.Value.ToShortDateString(), dateStop.Value.ToShortDateString());
        }

        private void dateStop_ValueChanged(object sender, EventArgs e)
        {
            int way = 0;
            if (rbtHouse.Checked == true)
            {
                way = 0;
            }
            else
            {
                if (rbtName.Checked == true)
                {
                    way = 1;
                }
                else
                {
                    if (rbtIdcard.Checked == true)
                    {
                        way = 2;
                    }
                    else
                    {
                        way = 3;
                    }
                }
            }
            RecordMenthod.tbRecordfoFind(lvMainRecord, tbxReserch.Text.Trim(), way, dateStart.Value.ToShortDateString(), dateStop.Value.ToShortDateString());
        }
    }
}
